<?php
/**
 * File:          KValidator_Parameter_Text_Filter
 * Description:   -
 * Author:        Kovac "Kovacou'" Alexandre (www.kovacou.fr)
 * Last Update:   21/04/2011
 */

   class KValidator_Parameter_Text_Filter implements KValidatorParameter {
      public  $filter;
      
      public function valid ($value, $config) {
         if ( ($this->filter === "int" || $this->filter === "integer") && false === filter_var($value, FILTER_VALIDATE_INT))
            return "Un nombre entier est requis.";
         elseif ( ($this->filter === "flt" || $this->filter === "float") && false === filter_var($value, FILTER_VALIDATE_FLOAT))
            return "Un nombre flottant est requis.";
         elseif ($this->filter === "url" && false === filter_var($value, FILTER_VALIDATE_URL))
            return "Une url valide est requise.";
         elseif ($this->filter === "ip" && false === filter_var($value, FILTER_VALIDATE_IP))
            return "Une adresse ip valide est requise.";
         elseif ( ($this->filter === "eml" || $this->filter === "email") && false === filter_var($value, FILTER_VALIDATE_EMAIL))
            return "Une email valide est requise.";
         elseif ($this->filter === "date") {
            $date = explode ("/", $value);
            
            if (false === isset ($date[2]) || false === checkdate ($date[1], $date[0], $date[2]))
               return "Une date valide est requise.";
         }
      }
   }
 
/**
 * End
 * Of
 * File
 */
?>